package com.luocc.ccdemo.db

import androidx.lifecycle.LiveData
import androidx.room.*
import com.luocc.ccdemo.entity.Video

@Dao
interface VideoDao {
    @Insert(onConflict = OnConflictStrategy.IGNORE)
    fun insert(video: Video)

    @Update
    fun update(video: Video)

    @Query("delete from video where id = :id")
    fun delete(id: Int)

    @Query("select * from video limit :count")
    fun findByCount(count: Int): LiveData<List<Video>>

    @Query("select * from video where id = :id")
    fun findById(id: Int): LiveData<Video>

    @Query("select * from video where seen = 1")
    fun findHistory(): LiveData<List<Video>>

    @Query("select * from video where collect = 1")
    fun findFavorites(): LiveData<List<Video>>

    @Query("delete from video where collect = 1")
    fun clearFavorites(): Int
}